package com.dgiot.myapplication;

import android.content.Context;

import android.content.res.AssetManager;

import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

import androidx.annotation.NonNull;

public class MySurfaceView extends SurfaceView implements SurfaceHolder.Callback {
    private EGLHelper eglHelper;
    public MySurfaceView(Context context) {
        this(context, null);
    }

    public MySurfaceView(Context context, AttributeSet attris) {
        super(context, attris);
        eglHelper = new EGLHelper(context.getAssets());
        getHolder().addCallback(this);
    }

    // 创建的时候
    @Override
    public void surfaceCreated(@NonNull SurfaceHolder surfaceHolder) {
        eglHelper.surfaceCreated(surfaceHolder.getSurface());
    }

    // 在surface的大小发生改变时触发
    @Override
    public void surfaceChanged(@NonNull SurfaceHolder surfaceHolder, int i, int i1, int i2) {
        eglHelper.surfaceChange(i1, i2);
    }

    // 在销毁时触发，
    @Override
    public void surfaceDestroyed(@NonNull SurfaceHolder surfaceHolder) {
        eglHelper.surfaceDestroyed();
    }
}
